import 'package:flutter/material.dart';

import 'knowledge_detail_child.dart';

class KnowledgeDetail extends StatefulWidget {
  final Map<String, dynamic> arguments;
  const KnowledgeDetail({super.key, required this.arguments});

  @override
  State<KnowledgeDetail> createState() => _KnowledgeDetailState();
}

class _KnowledgeDetailState extends State<KnowledgeDetail> with SingleTickerProviderStateMixin {
  late TabController _tabController;
  late final List<Tab> tabs = [];

  @override
  void initState() {
    super.initState();
    widget.arguments['tabs'].forEach((element) {
      tabs.add(Tab(text: element.name??''));
    });
    _tabController = TabController(vsync: this, length: tabs.length);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: TabBar(
          tabs: tabs,
          controller: _tabController,
          labelColor: Colors.amber,
          indicatorColor: Colors.amber,
          isScrollable: true,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        // physics: NeverScrollableScrollPhysics(),
        children: _child(),
      ),
    );
  }

  List<Widget> _child() {
    return widget.arguments['tabs'].map<Widget>((e) => KnowledgeDetailChild(cid: e.id??0)).toList();
  }
}